/*
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */
package com.sun.lwuit;

/**
 *
 * @author Chen Fishbein
 */
class SystemFont extends Font{
    
    private Object font;
    static Font defaultFont = new SystemFont(null);
    
    /**
     * Creates a new instance of SystemFont
     * 
     * @param face the face of the font, can be one of FACE_SYSTEM, 
     * FACE_PROPORTIONAL, FACE_MONOSPACE.
     * @param style the style of the font. 
     * The value is an OR'ed  combination of STYLE_BOLD, STYLE_ITALIC, and 
     * STYLE_UNDERLINED; or the value is zero (STYLE_PLAIN).
     * @param size the size of the font, can be one of SIZE_SMALL, 
     * SIZE_MEDIUM, SIZE_LARGE
     */
    public SystemFont(int face, int style, int size) {
        font = Display.getInstance().getImplementation().createFont(face, style, size);
    }
    
    /**
     * Creates a new instance of SystemFont using a MIDP Font object
     * @param font a MIDP javax.microedition.lcdui.Font object
     */
    public SystemFont(Object font) {
        this.font = font;
    }
    
    /**
     * Gets the advance width of the specified character in this Font. 
     * The advance width is the horizontal distance that would be occupied 
     * if ch were to be drawn using this Font, including inter-character 
     * spacing following ch necessary for proper positioning of subsequent text.
     * 
     * @param ch the character to be measured
     * @return the total advance width (a non-negative value)
     */
    public int charWidth(char ch) {
        return Display.getInstance().getImplementation().charWidth(font, ch);
    }


    /**
     * @inheritDoc
     */
    public int charsWidth(char[] ch, int offset, int length){
        return Display.getInstance().getImplementation().charsWidth(font, ch, offset, length);
    }
    
    /**
     * @inheritDoc
     */
    public int substringWidth(String str, int offset, int len){
        return Display.getInstance().getImplementation().stringWidth(font, str.substring(offset, offset + len));
    }
    
    /**
     * @inheritDoc
     */
    public int stringWidth(String str){
        return Display.getInstance().getImplementation().stringWidth(font, str);
    }
    
    /**
     * @inheritDoc
     */
    public int getHeight() {
        return Display.getInstance().getImplementation().getHeight(font);
    }

    /**
     * @inheritDoc
     */
    void drawChar(Graphics g, char character, int x, int y) {
    }

    /**
     * @inheritDoc
     */
    void drawChars(Graphics g, char[] data, int offset, int length, int x, int y) {
    }
    
    /**
     * Gets the face of the font.
     * 
     * @return one of FACE_SYSTEM, FACE_PROPORTIONAL, FACE_MONOSPACE
     */
    public int getFace(){
        return Display.getInstance().getImplementation().getFace(font);
    }
    
    /**
     * Gets the style of the font. The value is an OR'ed 
     * combination of STYLE_BOLD, STYLE_ITALIC, and STYLE_UNDERLINED; 
     * or the value is zero (STYLE_PLAIN).
     * 
     * @return style of the current font
     */
    public int getStyle(){
        return Display.getInstance().getImplementation().getStyle(font);
    }
    
    /**
     * Gets the size of the font.
     * 
     * @return one of SIZE_SMALL, SIZE_MEDIUM, SIZE_LARGE
     */
    public int getSize(){
        return Display.getInstance().getImplementation().getSize(font);
    }
    
    Object getNativeFont() {
        return font;
    }
}
